<template>
  <div class="createPost-main-container">
    <el-form ref="form" label-width="120px" :rules="rules" :model="form">
      <el-form-item label="内容" prop="value">
        <tinymce-editor
          ref="myEditor"
          upload-model="news"
          show-hyperlink-btn
        />
      </el-form-item>
    </el-form>
    <sticky :class-name="'cms-sub-navbar '+ajaxStatus">
      <el-button :loading="ajaxStatus" style="margin-left: 10px;" type="success" @click="submitForm()">
        发布
      </el-button>
      <el-button :loading="ajaxStatus" @click="reset()">
        取消
      </el-button>
    </sticky>
  </div>
</template>

<script>
import { getByCode, postData } from '@/api/contentConfig/index'
import Sticky from 'components/Sticky'

import TinymceEditor from 'components/ueditor'
export default {
  components: { TinymceEditor, Sticky },
  data() {
    return {
      signContent: '',
      ajaxStatus: false,
      form: {
        value: '',
        valueType: 'reachText',
        code: 'sign_content'
      }
    }
  },
  created() {
    getByCode({
      code: 'sign_content'
    }).then(res => {
      const { data } = res
      this.signContent = data.value
      this.form = Object.assign(this.form, data)
      this.$refs.myEditor.edit(data.value)
    })
  },
  methods: {
    submitForm() {
      this.ajaxStatus = true
      this.form.value = this.$refs.myEditor.onEditorChange()
      postData(this.form)
        .then(re => {
          this.ajaxStatus = false
          this.$notify({
            title: '成功',
            message: '操作成功',
            type: 'success',
            duration: 2000
          })
        })
        .catch(() => {
          this.ajaxStatus = false
        })
    }
  }
}
</script>

<style scoped>

</style>
